const cloud = require('wx-server-sdk');

const db = cloud.database()

exports.main = async (event,context)=>{
	let collectionName = event.collectionName;
	let method = event.method;
	let start = event.start;
	let count = event.count;
	let result;
	if(method === 'get'){
		// 获取需要转发的消息
		result = await db.collection(collectionName).where({
			state:'send'
		}).orderBy('create_at_utc','asc').limit(start*count).get();
	}else{
		// 修改状态
		result = await db.collection(collectionName).where({
			_id:event.id
		}).update({
			state:'success'
		})
	}
	return {'msg':'ok','data':result.data}
}